package com.cyyang.shop.controller;


import javax.servlet.http.HttpServletRequest;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cyyang.shop.bean.Brand;
import com.cyyang.shop.bean.Spec;
import com.cyyang.shop.service.SpecService;
import com.github.pagehelper.PageInfo;

@Controller
@RequestMapping("/spec")
public class SpecController {
	
	
	@Reference
	SpecService specService;
	
	
	@RequestMapping("list")
	public String list(HttpServletRequest req,@RequestParam(defaultValue = "1")Integer pageNum,@RequestParam(defaultValue = "6") Integer pageSize,Brand brand) {
		PageInfo<Spec> info = specService.list(pageNum, pageSize);
		req.setAttribute("info", info);
		return "/spec/list";
	}
	
	@RequestMapping("toAdd")
	public String toAdd() {
		return "spec/add";
	}
	@RequestMapping("toUpdate")
	public String toUpdate(HttpServletRequest req,Integer specId) {
		Spec spec = specService.findSpecBySpecId(specId);
		req.setAttribute("spec", spec);
		return "spec/update";
	}
	
	@RequestMapping("update")
	@ResponseBody
	public boolean update(Spec spec) {
		try {
			specService.update(spec);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		
	}
	
	
	@RequestMapping("add")
	@ResponseBody
	public boolean add(Spec spec) {
		try {
			specService.add(spec);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	
	@RequestMapping("delBatch")
	public String delBatch(String ids) {
		specService.delBatch(ids);
		return "redirect:/spec/list";
	}


	
	
	
	

}
